//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)

using NUnit.Framework;
using SoapTrace.Core.Communication;
using System;
using WinPcap;

namespace SoapTrace.Tests.SoapPacketMonitoring
{
	/// <summary>
	/// Tests that an IPPacketReceived event is triggered when an IP
	/// packet is processed by the <see cref="SoapPacketMonitorBase"/>.
	/// </summary>
	[ TestFixture ]
	public class IPPacketReceivedEventTestFixture : SoapPacketMonitorBase
	{
		IPPacket SentPacket;
		IPPacket ReceivedPacket;
		
		/// <summary>
		/// Initialise this test fixture.
		/// </summary>
		[ TestFixtureSetUp ]
		public void FixtureInit( )
		{
			base.IPPacketReceived += new PacketReceivedEventHandler( SentPacketReceived );
			
			byte[ ] Bytes = new byte[ ] { 0x0, 0x1, 0x2, 0x3 };
			SentPacket = new IPPacket( Bytes );
			
			base.ProcessIPPacket( SentPacket );
		}
		
		/// <summary>
		/// Check that we received the packet.
		/// </summary>
		[ Test ]
		public void ReceivedIPPacket( )
		{
			Assert.AreEqual( SentPacket, ReceivedPacket, "Expected to receive the same packet we sent." );
		}
		
		private void SentPacketReceived( object sender, PacketReceivedEventArgs e )
		{
			ReceivedPacket = ( IPPacket )( e.Packet );
		}
	}
}
